package com.qidian.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @date 2023/5/25 10:10
 */
@Configuration
public class ProducerConfig {
    @Bean
    public Queue queue(){
        // 参数1： 队列的名称，唯一标志
        // 参数2： 这个队列的消息是否要持久化存储
        return new Queue("stQueue",false);
    }


    // 配置交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        // 交换机对象
        //参数1： 交换机的名字
        //参数2: 是否持久化存储
        //参数3：不可用时，是否删除
        return new FanoutExchange("stFanoutExchange",true,false);
    }
    // 准备三个队列
    @Bean
    public Queue queueA(){
        return new Queue("stQueueA",true);
    }
    @Bean
    public Queue queueB(){
        return new Queue("stQueueB",true);
    }
    @Bean
    public Queue queueC(){
        return new Queue("stQueueC",true);
    }
    // 将三个队列绑定到交换机上
    @Bean
    public Binding bindingA(){
        return BindingBuilder.bind(queueA()).to(fanoutExchange());
    }
    @Bean
    public Binding bindingB(){
        return BindingBuilder.bind(queueB()).to(fanoutExchange());
    }
    @Bean
    public Binding bindingC(){
        return BindingBuilder.bind(queueC()).to(fanoutExchange());
    }


    @Bean
    public DirectExchange directExchange(){
        return  new DirectExchange("stDirectExchange",true,false);
    }

    // 准备三个队列
    @Bean
    public Queue queueM(){
        return new Queue("stQueueM",true);
    }
    @Bean
    public Queue queueN(){
        return new Queue("stQueueN",true);
    }
    @Bean
    public Queue queueP(){
        return new Queue("stQueueP",true);
    }
    // 将三个队列绑定到交换机上
    @Bean
    public Binding bindingM(){
        // 绑定之后，通过with指定这个队列的路由
        return BindingBuilder.bind(queueM()).to(directExchange()).with("tagSt");
    }
    @Bean
    public Binding bindingN(){
        // 绑定之后，通过with指定这个队列的路由
        return BindingBuilder.bind(queueN()).to(directExchange()).with("tagSt");
    }
    @Bean
    public Binding bindingP(){
        // 绑定之后，通过with指定这个队列的路由
        return BindingBuilder.bind(queueP()).to(directExchange()).with("tagSq");
    }



    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("stTopicExchange",true,false);
    }

    // 准备三个队列
    @Bean
    public Queue queueH(){
        return new Queue("stQueueH",true);
    }
    @Bean
    public Queue queueJ(){
        return new Queue("stQueueJ",true);
    }
    @Bean
    public Queue queueK(){
        return new Queue("stQueueK",true);
    }

    // 将三个队列绑定到交换机上
    @Bean
    public Binding bindingH(){
        // 绑定之后，通过with指定这个队列的路由
        return BindingBuilder.bind(queueH()).to(topicExchange()).with("topic.*");
    }
    @Bean
    public Binding bindingJ(){
        // 绑定之后，通过with指定这个队列的路由
        return BindingBuilder.bind(queueJ()).to(topicExchange()).with("topic.#");
    }
    @Bean
    public Binding bindingK(){
        // 绑定之后，通过with指定这个队列的路由
        return BindingBuilder.bind(queueK()).to(topicExchange()).with("topic.#");
    }


    @Bean
    public TopicExchange topicExchange1(){
        return new TopicExchange("stTopicExchange1",true,false);
    }
}
